home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / iomanip.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  6.0 KB  |  255 lines

  1. #ifndef __STD_IOMANIP__
  2. #define __STD_IOMANIP__
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * iomanip - Declarations for the Standard Library iomanip classes
  8.  *
  9.  * $Id: iomanip,v 1.22 1996/08/28 01:28:48 smithey Exp $
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  14.  * ALL RIGHTS RESERVED *
  15.  * The software and information contained herein are proprietary to, and
  16.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  17.  * intends to preserve as trade secrets such software and information.
  18.  * This software is furnished pursuant to a written license agreement and
  19.  * may be used, copied, transmitted, and stored only in accordance with
  20.  * the terms of such license and with the inclusion of the above copyright
  21.  * notice.  This software and information or any other copies thereof may
  22.  * not be provided or otherwise made available to any other person.
  23.  *
  24.  * Notwithstanding any other lease or license that may pertain to, or
  25.  * accompany the delivery of, this computer software and information, the
  26.  * rights of the Government regarding its use, reproduction and disclosure
  27.  * are as set forth in Section 52.227-19 of the FARS Computer
  28.  * Software-Restricted Rights clause.
  29.  *
  30.  * Use, duplication, or disclosure by the Government is subject to
  31.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  32.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  33.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  34.  * P.O. Box 2328, Corvallis, Oregon 97339.
  35.  *
  36.  * This computer software and information is distributed with "restricted
  37.  * rights."  Use, duplication or disclosure is subject to restrictions as
  38.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  39.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  40.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  41.  * then the "Alternate III" clause applies.
  42.  *
  43.  **************************************************************************/
  44.  
  45. #include <stdcomp.h>
  46. #include <iosfwd>
  47. #include <iostream>
  48.  
  49. #ifndef _RWSTD_NO_NAMESPACE
  50. namespace std {
  51. #endif
  52.   
  53.   
  54. /*
  55.  * class smanip
  56.  *
  57.  */
  58.  
  59. template<class T>
  60. class smanip {
  61.  
  62.   public:
  63.  
  64.     smanip(ios_base& (*pf)(ios_base&, T), T manarg)
  65.     : pf_(pf)
  66.     , manarg_(manarg)
  67.      { ; }
  68.  
  69.  
  70.     ios_base&           (*pf_)(ios_base&, T);
  71.     T              manarg_;
  72.  
  73.   protected:
  74.  
  75.   private:
  76.  
  77. };
  78.  
  79. /*
  80.  * class smanip_fill
  81.  *
  82.  */
  83.  
  84. template<class T, class traits>
  85. class smanip_fill {
  86.  
  87.   public:
  88.  
  89.     smanip_fill(basic_ios< T, traits >& (*pf)(basic_ios< T, traits >&, T), T manarg)
  90.     : pf_(pf)
  91.     , manarg_(manarg)
  92.      { ; }
  93.  
  94.  
  95.     basic_ios< T, traits >&   (*pf_)(basic_ios< T, traits >&, T);
  96.     T              manarg_;
  97.  
  98.   protected:
  99.  
  100.   private:
  101.  
  102. };
  103.  
  104.  
  105. /*
  106.  * global manipulators
  107.  */
  108.  
  109.  
  110. inline ios_base& rsios(ios_base& str, ios_base::fmtflags mask)
  111. {
  112.   str.setf((ios_base::fmtflags)0, mask);
  113.  
  114.   return str;
  115. }
  116.  
  117.  
  118. inline ios_base& sios(ios_base& str, ios_base::fmtflags mask)
  119. {
  120.   str.setf(mask);
  121.  
  122.   return str;
  123. }
  124.  
  125.  
  126. inline ios_base& sbase(ios_base& str, int base)
  127. {
  128.   str.setf(base == 8 ? ios_base::oct :
  129.        base == 10 ? ios_base::dec :
  130.        base == 16 ? ios_base::hex :
  131.        ios_base::fmtflags(0), ios_base::basefield);
  132.  
  133.   return str;
  134. }
  135.  
  136. template < class charT, class traits >
  137. inline basic_ios< charT, traits >& sfill( basic_ios< charT, traits >& str, charT c)
  138. {
  139.   str.fill(c);
  140.  
  141.   return str;
  142. }
  143.  
  144. inline ios_base& sprec(ios_base& str, int n)
  145. {
  146.   str.precision(n);
  147.  
  148.   return str;
  149. }
  150.  
  151. inline ios_base& swidth(ios_base& str, int n)
  152. {
  153.   str.width(n);
  154.  
  155.   return str;
  156. }
  157.  
  158.  
  159. inline smanip<ios_base::fmtflags> resetiosflags(ios_base::fmtflags mask )
  160. { return smanip<ios_base::fmtflags>(rsios, mask); }
  161.  
  162. inline smanip<ios_base::fmtflags> setiosflags(ios_base::fmtflags mask )
  163. { return smanip<ios_base::fmtflags>(sios, mask); }
  164.  
  165. inline smanip<int> setbase(int base)
  166. { return smanip<int>(sbase, base); }
  167.  
  168. template < class charT >
  169. inline smanip_fill<charT, char_traits<charT> > setfill( charT c)
  170. { return smanip_fill<charT, char_traits<charT> >(
  171.   (basic_ios< charT, char_traits<charT> >& (*)(basic_ios< charT,
  172.      char_traits<charT> >&, charT))sfill, c); 
  173. }
  174.  
  175. inline smanip<int> setprecision(int n)
  176. { return smanip<int>(sprec, n); }
  177.  
  178. inline smanip<int> setw(int n)
  179. { return smanip<int>(swidth, n); }
  180.  
  181. template<class charT, class traits, class T>
  182. inline basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, const smanip<T>& a)
  183. {
  184. #ifndef _RWSTD_NO_EXCEPTIONS
  185.   try {
  186.     (*a.pf_)(is, a.manarg_);
  187.   }
  188.   catch(...) {
  189.     is.setstate(ios_base::failbit);
  190.   }
  191. #else
  192.   (*a.pf_)(is, a.manarg_);
  193. #endif
  194.   
  195.   return is;
  196. }
  197.  
  198. template<class charT, class traits, class T>
  199. inline basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const smanip<T>& a)
  200. {
  201. #ifndef _RWSTD_NO_EXCEPTIONS
  202.   try {
  203.     (*a.pf_)(os, a.manarg_);
  204.   }
  205.   catch(...) {
  206.     os.setstate(ios_base::failbit);
  207.   }
  208. #else
  209.   (*a.pf_)(os, a.manarg_);
  210. #endif
  211.   
  212.   return os;
  213. }
  214.  
  215. template<class T, class traits>
  216. inline basic_istream<T, traits>& operator>>(basic_istream<T, traits>& is, const smanip_fill<T, traits>& a)
  217. {
  218. #ifndef _RWSTD_NO_EXCEPTIONS
  219.   try {
  220.     (*a.pf_)(is, a.manarg_);
  221.   }
  222.   catch(...) {
  223.     is.setstate(ios_base::failbit);
  224.   }
  225. #else
  226.   (*a.pf_)(is, a.manarg_);
  227. #endif
  228.   
  229.   return is;
  230. }
  231.  
  232. template<class T, class traits>
  233. inline basic_ostream<T, traits>& operator<<(basic_ostream<T, traits>& os, const smanip_fill<T, traits>& a)
  234. {
  235. #ifndef _RWSTD_NO_EXCEPTIONS
  236.   try {
  237.     (*a.pf_)(os, a.manarg_);
  238.   }
  239.   catch(...) {
  240.     os.setstate(ios_base ::failbit);
  241.   }
  242. #else
  243.   (*a.pf_)(os, a.manarg_);
  244. #endif
  245.   
  246.   return os;
  247. }
  248.  
  249. #ifndef _RWSTD_NO_NAMESPACE
  250. }
  251. #endif
  252.  
  253. #pragma option pop
  254. #endif /* __IOMANIP__ */
  255.